package com.wandian.news.mvvm.knowledge.scjs.scjsother;

import android.os.Bundle;
import android.view.View;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.mylib.libcore.config.RouterConfig;
import com.mylib.libcore.mvvm.BaseMVVMActivity;
import com.mylib.libcore.utils.ActivityUtil;
import com.mylib.libcore.utils.UIUtils;
import com.wandian.news.R;
import com.wandian.news.adapter.KnowledgeJXSCRecycleAdapter;
import com.wandian.news.adapter.KnowledgeTSDQRecycleAdapter;
import com.wandian.news.adapter.KnowledgeTSRecycleAdapter;
import com.wandian.news.adapter.KnowledgeYMSJRecycleAdapter;
import com.wandian.news.adapter.KnowledgeYQRecycleAdapter;
import com.wandian.news.databinding.NewsActivityKnowledgeScjsBinding;
import com.wandian.news.databinding.NewsActivityKnowledgeScjsOtherBinding;

/**
 * @author Administrator
 * @date 2019/12/18-14:28
 * @description 诗词鉴赏其他activity
 **/
@Route(path = RouterConfig.ROUTER_ACTIVITY_NEWS_SCJS_OTHER)
public class KnowledgeSCJSOtherActivity extends BaseMVVMActivity<KnowledgeSCJSOtherViewModel>   {
    private NewsActivityKnowledgeScjsOtherBinding dataBinding;
    private KnowledgeTSDQRecycleAdapter tsdqAdapter;
    private KnowledgeTSRecycleAdapter tsAdapter;
    private KnowledgeYQRecycleAdapter yqAdapter;
    private KnowledgeJXSCRecycleAdapter jxscAdapter;
    private KnowledgeYMSJRecycleAdapter ymsjAdapter;
    private String title="";
    private int page = 1;
    @Override
    public void init(Bundle savedInstanceState) {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.news_activity_knowledge_scjs_other);
        dataBinding.setLifecycleOwner(this);
        dataBinding.setViewModel(mViewModel);
        title = getIntent().getStringExtra("title")+"";
        initViewData();
        initClink();
        initRecycle();
    }

    private void initRecycle(){
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
        dataBinding.recycler.setLayoutManager(layoutManager);
        switch (title){
            case "元曲":
                yqAdapter = new KnowledgeYQRecycleAdapter(R.layout.news_item_knowledge_yq_style);
                dataBinding.recycler.setAdapter(yqAdapter);
                mViewModel.listYQ.observe(this,listYQ->{
                    if(!UIUtils.isEmpty(listYQ) && listYQ.size()>0)yqAdapter.setNewData(listYQ);
                });
                break;
            case "唐诗":
                tsAdapter = new KnowledgeTSRecycleAdapter(R.layout.news_item_knowledge_ts_style);
                dataBinding.recycler.setAdapter(tsAdapter);
                mViewModel.listTS.observe(this,listTS->{
                    if(!UIUtils.isEmpty(listTS) && listTS.size()>0)tsAdapter.setNewData(listTS);
                });
                break;
            case "精选宋词":
                jxscAdapter = new KnowledgeJXSCRecycleAdapter(R.layout.news_item_knowledge_jxsc_style);
                dataBinding.recycler.setAdapter(jxscAdapter);
                mViewModel.listJXSC.observe(this,listJXSC->{
                    if(!UIUtils.isEmpty(listJXSC) && listJXSC.size()>0)jxscAdapter.setNewData(listJXSC);
                });
                break;
            case "优美诗句":
                ymsjAdapter = new KnowledgeYMSJRecycleAdapter(R.layout.news_item_knowledge_jxsc_style);
                dataBinding.recycler.setAdapter(ymsjAdapter);
                mViewModel.listYMSJ.observe(this,listYMSJ->{
                    if(!UIUtils.isEmpty(listYMSJ) && listYMSJ.size()>0)ymsjAdapter.setNewData(listYMSJ);
                });
                break;
            case "唐诗大全":
                tsdqAdapter = new KnowledgeTSDQRecycleAdapter(R.layout.news_item_knowledge_tsdq_style);
                dataBinding.recycler.setAdapter(tsdqAdapter);
                mViewModel.listTSDQ.observe(this,listTSDQ->{
                    if(!UIUtils.isEmpty(listTSDQ) && listTSDQ.size()>0)tsdqAdapter.setNewData(listTSDQ);
                });
                break;
        }
        getDataTitle(title);
    }

    private void getDataTitle(String title){
        mViewModel.getDataTitle(title,page+"");
    }

    private void initViewData(){
        ActivityUtil.getInstance().showStatusView(this,dataBinding.viewSysTop,true);
        dataBinding.bindTransparentToolBar.toolBarTvTitle.setText(title+"");
        dataBinding.bindTransparentToolBar.toolBarTitleRight.setText("换一换");
        dataBinding.bindTransparentToolBar.toolBarTitleRight.setVisibility(View.VISIBLE);

    }


    private void initClink(){
        dataBinding.bindTransparentToolBar.toolBarIvBack.setOnClickListener(v -> finish());
        dataBinding.bindTransparentToolBar.toolBarTitleRight.setOnClickListener(v -> {
            page++;
            getDataTitle(title);
        });
    }



    @Override
    protected void onDestroy() {
        super.onDestroy();
    }


}
